﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Master/SiteContent.Master" AutoEventWireup="true"
    CodeBehind="Suppliers.aspx.cs" Inherits="Warehouse.Web.Management.Suppliers" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <style type="text/css">
        .moduleheader .moduleheadertoolbar > * {
            margin: 16px 5px 0 5px;
        }
        .datatable {
            min-width: 100%;
        }
        .col_name {
            width: 120px;
        }
        .col_code {
            width: 80px;
        }
        .col_address {
        }
        .col_telephone {
            width: 80px;
        }
        .col_op {
            width: 60px;
        }
    </style>

    <script type="text/javascript">
        function addItem() {
            var html = ['<div class="dialog">'];
            html.push('<table class="infotable">');
            html.push('<tr><td><label>名称</label></td><td><input type="text" field="Name"/></td></tr>');
            html.push('<tr><td><label>代码</label></td><td><input type="text" field="Code"/></td></tr>');
            html.push('<tr><td><label>地址</label></td><td><input type="text" field="Address"/></td></tr>');
            html.push('<tr><td><label>电话</label></td><td><input type="text" field="Telephone"/></td></tr>');
            html.push('</table>');
            html.push('</div>');
            var dialog = top.showDialog(html.join(''), { title: "添加供货商",
                width: 300,
                height: 240,
                resizable: false,
                modal: true,
                buttons: {
                    "确定": function() {
                        var data = Util.getFields(dialog);
                        if (!data.Name) {
                            alert("请输入名称");
                            return;
                        }
                        data.HouseType = data.HouseType - 0;
                        Util.post("", $.extend(true, { action: "Add" }, data), function(succeed, data, err) {
                            if (succeed) {
                                alert('保存成功');
                                dialog.dialog('close');
                                window.location.reload();
                            } else {
                                alert(err);
                            }
                        }, { autoOverlay: true });
                    },
                    "取消": function() {
                        dialog.dialog('close');
                    }
                }
            });
        }
        function modifyItem(supplierId) {
            Util.get("", { action: "Get", SupplierID: supplierId }, function(succeed, data, err) {
                if (succeed) {
                    var html = ['<div class="dialog">'];
                    html.push('<table class="infotable">');
                    html.push('<tr><td><label>名称</label></td><td><input type="hidden" field="ID" value="' + data.ID + '"/><input type="text" field="Name" value="' + data.Name + '"/></td></tr>');
                    html.push('<tr><td><label>代码</label></td><td><input type="text" field="Code" value="' + data.Code + '"/></td></tr>');
                    html.push('<tr><td><label>地址</label></td><td><input type="text" field="Address" value="' + data.Address + '"/></td></tr>');
                    html.push('<tr><td><label>电话</label></td><td><input type="text" field="Telephone" value="' + data.Telephone + '"/></td></tr>');
                    html.push('</table>');
                    html.push('</div>');
                    var dialog = top.showDialog(html.join(''), { title: "编辑供货商",
                        width: 300,
                        height: 240,
                        resizable: false,
                        modal: true,
                        buttons: {
                            "确定": function() {
                                var data = Util.getFields(dialog);
                                if (!data.Name) {
                                    alert("请输入名称");
                                    return;
                                }
                                Util.post("", $.extend(true, { action: "Save" }, data), function(succeed, data, err) {
                                    if (succeed) {
                                        alert('保存成功');
                                        dialog.dialog('close');
                                        window.location.reload();
                                    } else {
                                        alert(err);
                                    }
                                }, { autoOverlay: true });
                            },
                            "取消": function() {
                                dialog.dialog('close');
                            }
                        }
                    });
                } else {
                    alert(err);
                }
            }, { autoOverlay: true });
        }
        function deleteItem(supplierId) {
            if (confirm("您确认要删除该供货商吗？")) {
                Util.post("", { action: "Delete", SupplierID: supplierId }, function(succeed, data, err) {
                    if (succeed) {
                        alert('删除成功');
                        window.location.reload();
                    } else {
                        alert(err);
                    }
                }, { autoOverlay: true });
            }
        }
    </script>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div class="moduleheader">
        <h4>
            供货商管理</h4>
        <div class="moduleheadertoolbar">
            <input type="button" class="ui-button-refresh" onclick="window.location.reload();"
                value="刷新" />
            <uc:AuthorityControl ID="AuthorityControl1" runat="server" Action="Add">
                <input type="button" class="ui-button-add" onclick="addItem();" value="添加供货商" />
            </uc:AuthorityControl>
        </div>
    </div>
    <div class="modulecontent">
        <table class="datatable">
            <tr>
                <th class="col_name">
                    供货商
                </th>
                <th class="col_code">
                    代码
                </th>
                <th class="col_address">
                    地址
                </th>
                <th class="col_telephone">
                    电话
                </th>
                <th class="col_op">
                    管理
                </th>
            </tr>
            <asp:Repeater ID="rptItems" runat="server">
                <ItemTemplate>
                    <tr>
                        <td class="col_name">
                            <%# Eval("Name") %>
                        </td>
                        <td class="col_code">
                            <%# Eval("Code") %>
                        </td>
                        <td class="col_address">
                            <%# Eval("Address")%>
                        </td>
                        <td class="col_telephone">
                            <%# Eval("Telephone")%>
                        </td>
                        <td class="col_op">
                            <uc:AuthorityControl ID="AuthorityControl2" runat="server" Action="Save">
                                <input type="button" class="icon-button-edit" value=" " onclick="modifyItem(<%# Eval("ID") %>)"
                                    title="编辑" />
                            </uc:AuthorityControl>
                            <uc:AuthorityControl ID="AuthorityControl3" runat="server" Action="Delete">
                                <input type="button" class="icon-button-delete" value=" " onclick="deleteItem(<%# Eval("ID") %>)"
                                    title="删除" />
                            </uc:AuthorityControl>
                        </td>
                    </tr>
                </ItemTemplate>
            </asp:Repeater>
        </table>
    </div>
</asp:Content>
